package com.fzhucc.modules.lesson.repository;

import com.fzhucc.modules.lesson.domain.Lesson;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
* @website https://eladmin.vip
* @author yyg
* @date 2022-12-07
**/
public interface LessonRepository extends JpaRepository<Lesson, Integer>, JpaSpecificationExecutor<Lesson> {

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1 and org_area=:orgArea and is_delete=0 and is_push=:isPush and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPushByOrgArea(int isPush,String orgArea, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1 and org_area=:orgArea and is_delete=0 and is_push=:isPush and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPushWithTypeByOrgArea(int isPush,String orgArea, String type, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1 and org_area=:orgArea and is_delete=0 and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithTypeByOrgArea(String type,String orgArea, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1 and org_area=:orgArea and is_delete=0 and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListByOrgArea(String orgArea,Pageable pageable);


    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and is_push=:isPush and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPush(int isPush, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and is_push=:isPush and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPushWithType(int isPush, String type, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0)) order by sort")
    Page<Lesson> findWxListWithType(String type, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxList(Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithTypeByNoOrgArea(String type, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and is_push=:isPush and type=:type and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPushWithTypeByNoOrgArea(int isPush, String type, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListByNoOrgArea(Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * from tb_lesson where (is_show=1  and is_delete=0 and is_push=:isPush and ((is_unlimited_time=1 and starttime<=NOW() and endtime>=NOW()) or is_unlimited_time=0) )order by sort")
    Page<Lesson> findWxListWithIsPushByNoOrgArea(int isPush, Pageable pageable);
}
